import { message } from "ant-design-vue";
import axios from "axios";

const service = axios.create({
    baseURL: '/api',
    timeout: 5000
})

//请求拦截器
service.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

//响应拦截器
service.interceptors.response.use(
    response => {
        const res = response.data
        if(res.code !== 200){
            message.error(res.message || 'Error')
            return Promise.reject(new Error(res.message))
        }
        return res
    },
    error => {
        message.error(error.message || 'Error')
        return Promise.reject(error)
    }
)

export default service